// 所有图表映射关系都从此文件出去，不允许在业务代码定义映射关系
import cloneDeep from 'lodash/cloneDeep';
import { Materiel } from '@/model/types/field';
// 会根据\w+Controls(_\w+)?$匹配出echarts的options
import {
  dataLabelControls,
  flexLayoutControls,
  legendControls,
  xAxisControls,
  yAxisControls,
  toolboxControls,
  seriesControls_pie,
  seriesControls,
  tooltipControls,
  dataZoomControls,
  dataZoomControls_strip,
  tableControls,
  paginationControls,
} from '@/model/designer/fieldControl';
import {
  Sort,
  Alias,
  Aggregation,
  PeriodType,
  DataFormat,
  HighCalc,
  Remove,
  EditFilter,
} from '@/components/cardDesign/constant';

export const materielList: Materiel[] = [
  {
    type: 'table',
    componentType: 'card',
    icon: 'icon_rb-table',
    label: '简单表',
    tip: '0个或多个维度，0个或多个度量',
    controls: { tableControls, paginationControls },
    component: () => import('@/components/chart/table/Index.vue'),
    options: () => import('@/components/chart/table/index'),
    staticJson: () => import('@/components/chart/table/staticJson'),
    layout: {
      w: 24,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 10,
        extension: [PeriodType, Remove],
      },
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 10,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'multivalue',
    componentType: 'card',
    icon: 'icon_rb-multivalue',
    label: '多值图',
    tip: '多个度量',
    controls: {
      dataLabelControls,
      flexLayoutControls,
    },
    component: () => import('@/components/chart/multivalue/Index.vue'),
    options: () => import('@/components/chart/multivalue/index'),
    staticJson: () => import('@/components/chart/multivalue/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 10,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'bar',
    componentType: 'card',
    icon: 'icon_rb-bar-chart',
    label: '柱状图',
    tip: '1个维度，1个或多个度量',
    controls: {
      legendControls,
      xAxisControls,
      yAxisControls,
      toolboxControls,
      seriesControls,
      tooltipControls,
      dataZoomControls,
    },
    component: () => import('@/global/components/EchartWrapper.vue'),
    options: () => import('@/components/chart/bar/index'),
    staticJson: () => import('@/components/chart/bar/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 10,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'legend',
        axisLabel: '系列',
        max: 1,
        extension: [Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'strip',
    componentType: 'card',
    icon: 'icon_rb-strip-chart',
    label: '条形图',
    tip: '1个维度，1个度量',
    controls: {
      legendControls,
      xAxisControls,
      yAxisControls,
      toolboxControls,
      seriesControls,
      tooltipControls,
      dataZoomControls_strip,
    },
    component: () => import('@/global/components/EchartWrapper.vue'),
    options: () => import('@/components/chart/strip/index'),
    staticJson: () => import('@/components/chart/strip/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 10,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'legend',
        axisLabel: '系列',
        max: 1,
        extension: [Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'pie',
    componentType: 'card',
    icon: 'icon_rb-pie-chart',
    label: '饼图',
    tip: '1个维度，1个度量',
    controls: {
      legendControls,
      toolboxControls,
      seriesControls_pie,
      tooltipControls,
    },
    component: () => import('@/global/components/EchartWrapper.vue'),
    options: () => import('@/components/chart/pie/index'),
    staticJson: () => import('@/components/chart/pie/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 1,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'ring',
    componentType: 'card',
    icon: 'icon_rb-ring-chart',
    label: '环形图',
    tip: '1个维度，1个度量',
    controls: {
      legendControls,
      toolboxControls,
      seriesControls_pie,
      tooltipControls,
    },
    component: () => import('@/global/components/EchartWrapper.vue'),
    options: () => import('@/components/chart/ring/index'),
    staticJson: () => import('@/components/chart/ring/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 1,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'nightingale',
    componentType: 'card',
    icon: 'icon_rb-nightingale',
    label: '南丁格尔图',
    tip: '1个维度，1个度量',
    controls: {
      legendControls,
      toolboxControls,
      seriesControls_pie,
      tooltipControls,
    },
    component: () => import('@/global/components/EchartWrapper.vue'),
    options: () => import('@/components/chart/nightingale/index'),
    staticJson: () => import('@/components/chart/nightingale/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 1,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'line',
    componentType: 'card',
    icon: 'icon_rb-line-chart',
    label: '折线图',
    tip: '1个维度，1个或多个度量',
    controls: {
      legendControls,
      xAxisControls,
      yAxisControls,
      toolboxControls,
      seriesControls,
      tooltipControls,
      dataZoomControls,
    },
    component: () => import('@/global/components/EchartWrapper.vue'),
    options: () => import('@/components/chart/line/index'),
    staticJson: () => import('@/components/chart/line/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 10,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'legend',
        axisLabel: '系列',
        max: 1,
        extension: [Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'stack',
    componentType: 'card',
    icon: 'icon_rb-stack-chart',
    label: '堆叠图',
    tip: '1个维度，1个或多个度量',
    controls: {
      legendControls,
      xAxisControls,
      yAxisControls,
      toolboxControls,
      seriesControls,
      tooltipControls,
      dataZoomControls,
    },
    component: () => import('@/global/components/EchartWrapper.vue'),
    options: () => import('@/components/chart/stack/index'),
    staticJson: () => import('@/components/chart/stack/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 10,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'legend',
        axisLabel: '系列',
        max: 1,
        extension: [Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'biaxial',
    componentType: 'card',
    icon: 'icon_rb-biaxial-chart',
    label: '双轴图',
    tip: '1个维度，2个或多个度量',
    controls: {
      legendControls,
      xAxisControls,
      yAxisControls,
      toolboxControls,
      seriesControls,
      tooltipControls,
      dataZoomControls,
    },
    component: () => import('@/global/components/EchartWrapper.vue'),
    options: () => import('@/components/chart/biaxial/index'),
    staticJson: () => import('@/components/chart/biaxial/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 10,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'legend',
        axisLabel: '系列',
        max: 1,
        extension: [Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'radar',
    componentType: 'card',
    icon: 'icon_rb-radar-chart',
    label: '雷达图',
    tip: '1个维度，1个或多个度量',
    controls: {
      legendControls,
      toolboxControls,
      seriesControls,
      tooltipControls,
    },
    component: () => import('@/global/components/EchartWrapper.vue'),
    options: () => import('@/components/chart/radar/index'),
    staticJson: () => import('@/components/chart/radar/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 10,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'legend',
        axisLabel: '系列',
        max: 1,
        extension: [Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'gauge',
    componentType: 'card',
    icon: 'icon_rb-guage-chart',
    label: '仪表盘',
    tip: '1个度量',
    controls: {
      legendControls,
      toolboxControls,
      seriesControls,
      tooltipControls,
    },
    component: () => import('@/global/components/EchartWrapper.vue'),
    options: () => import('@/components/chart/gauge/index'),
    staticJson: () => import('@/components/chart/gauge/staticJson'),
    layout: {
      w: 12,
      h: 12,
      minW: 4,
      minH: 4,
    },
    axesList: [
      {
        axisLocation: 'measure',
        axisLabel: '度量',
        max: 1,
        extension: [Aggregation, Remove],
      },
      {
        axisLocation: 'filtrate',
        axisLabel: '筛选',
        max: 1,
        extension: [EditFilter, PeriodType, Remove],
      },
    ],
  },
  {
    type: 'listFilter',
    componentType: 'listFilter',
    icon: 'icon_rb-list-filter',
    label: '列表筛选',
    tip: '',
    controls: {},
    component: () => import('@/components/comp/listFilter/Index.vue'),
    options: () => null,
    staticJson: () => null,
    layout: {
      w: 12,
      h: 2,
      minW: 4,
      minH: 2,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
      // {
      //   axisLocation: 'filtrate',
      //   axisLabel: '筛选',
      //   max: 1,
      //   extension: [EditFilter, Remove],
      // },
    ],
  },
  {
    type: 'dateFilter',
    componentType: 'dateFilter',
    icon: 'icon_rb-date-filter',
    label: '日期筛选',
    tip: '',
    controls: {},
    component: () => import('@/components/comp/dateFilter/Index.vue'),
    options: () => null,
    staticJson: () => null,
    layout: {
      w: 12,
      h: 2,
      minW: 4,
      minH: 2,
    },
    axesList: [
      {
        axisLocation: 'dim',
        axisLabel: '维度',
        max: 1,
        extension: [PeriodType, Remove],
      },
    ],
  },
  {
    type: 'tab',
    componentType: 'tab',
    icon: 'icon_rb-headline',
    label: 'tab页签',
    tip: '',
    controls: {},
    component: () => import('@/components/gridLayout/TabContainer.vue'),
    options: () => null,
    staticJson: () => null,
    customStyleComp: () => import('@/components/gridLayout/TabCustomStyle.vue'),
    layout: {
      w: 12,
      h: 12,
      minW: 12,
      minH: 6,
    },
    axesList: null,
  },
  {
    type: 'headerH1',
    componentType: 'headerH1',
    icon: 'icon_rb-headline',
    label: '标题',
    tip: '',
    controls: {},
    component: () => import('@/components/comp/headerH1/Index.vue'),
    options: () => null,
    staticJson: () => null,
    layout: {
      w: 24,
      h: 2,
      minW: 4,
      minH: 1,
    },
    axesList: null,
  },
];

export const getMateriel = (type: string): Materiel => {
  const materiel = materielList.find((it) => it.type === type);
  if (materiel) {
    return cloneDeep(materiel);
  } else if (type) {
    // message.warning('未找到对应物料！');
  }
  return {} as Materiel;
};
